package io.ewolf.ssm.service.impl;

import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

import io.ewolf.ssm.mapper.ItemCustomMapper;
import io.ewolf.ssm.mapper.ItemMapper;
import io.ewolf.ssm.po.Item;
import io.ewolf.ssm.po.ItemCustom;
import io.ewolf.ssm.po.ItemQueryVo;
import io.ewolf.ssm.service.ItemService;

public class ItemServiceImpl implements ItemService {

	@Autowired
	private ItemCustomMapper itemCustomMapper;
	@Autowired
	private ItemMapper itemMapper;

	@Override
	public List<ItemCustom> findItemList(ItemQueryVo itemQueryVo) throws Exception {
		// 通过itemCustomMapper 查询数据库
		return itemCustomMapper.findItemList(itemQueryVo);
	}

	@Override
	public ItemCustom findItemById(int id) throws Exception {
		Item item = itemMapper.findItemById(id);
		// 中间对商品进行业务处理

		// ......

		// 最终返回扩展类ItemCustem
		ItemCustom itemCustem = new ItemCustom();
		// 将item的属性值拷贝到itemCustom
		BeanUtils.copyProperties(item, itemCustem);

		return itemCustem;
	}

	@Override
	public void updateItem(Integer id, ItemCustom itemCustom) throws Exception {
		// 添加业务校验，通常在service接口对关键参数进行校验
		// 校验id是否为空，如果为空，抛出异常
		// ......

		// 必须要传入id
		itemCustom.setId(id);
		itemCustomMapper.updateById(itemCustom);
	}

	@Override
	public void deleteItem(Integer id) throws Exception {

		itemCustomMapper.deleteItemById(id);

	}

	@Override
	public void deleteItemByArray(ItemQueryVo itemQueryVo) throws Exception {
		itemCustomMapper.deleteItemByArray(itemQueryVo);
	}

	@Override
	public void updateByList(ItemQueryVo itemQueryVo) throws Exception {
		itemCustomMapper.updateByList(itemQueryVo);
	}

}
